<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html>
<html>
<head>
<jsp:include page="../head.jsp">
<jsp:param value="部门管理" name="title"/>
</jsp:include>
<script type="text/javascript">
	$(function() {		
		//批量删除按钮事件
		$('#delete').on(
				'click',
				function() {
					//获取所有选中
					var checkeds = $(".item-check:checked");
					if (checkeds.length && confirm("确认要删除所有选中行吗？")) {
						//获取所有选择的id
						var ids = [];
						var upids = [];
						checkeds.each(function() {
							ids.push(this.value);
							upids.push($("#aa").val());
						});
						location.replace("dept/delete?id="
								+ ids.join("&id=") + "&updeptId="+ upids.join("&updeptId=") );
					}
					return;
			});
		
		//初始化插件和元素
		jQuery(document).ready(function() {		
			App.setPage("dept_manager");  //Set current page
			App.init(); //Initialise plugins and elements
		});
	});
</script>
</head>
<body>
	<div class="container">
		<div class="row">
		<div id="content" class="col-lg-12">
			<div class = "dao">		
				<p>部门管理</p>					
			</div>			
				<div class="row">
					<div class="col-md-12">
						<!-- BOX -->
						<div class="box border blue">
							<div class="box-title">
								<h4>部门列表</h4>
							</div>
							<div class="dataTables_header clearfix">
							   <div class="col-md-4">
							   <div style = "padding: 10px">
								<div>
									<a href="dept" class="ui button"> <i class="icon user"></i>
										新建部门
									</a>
									<button class="ui button" id="delete">
										<i class="icon trash"></i> 删除部门
									</button>
								</div>
									<span style="color:red;">${error }</span>	
								</div>
							    </div>
							   </div>
							<div class="box-body center">
								<table id="datatable2" cellpadding="0" cellspacing="0" border="0" class="datatable table table-striped table-bordered table-hover">
									<thead >
										<tr style = "text-align: center">
											<th>
												<div>
													<input type="checkbox" id="checkAll">
												</div>
											</th>
											<th>部门名称</th>
											<th>部门经理</th>
											<th class="hidden-xs">上属部门</th>
											<th>编辑&nbsp;删除</th>
											
										</tr>
									</thead>
									<tbody>
										<c:forEach items="${dept }" var="dept">
										<tr class="gradeX">
											<td>
												<div>
													<input class="item-check input" type="checkbox" value="${dept.dept_id }">
												</div>
													<input class="item-check" type="hidden" id="aa" value="${dept.updapt_id }">
											</td>
											<td><a href="dept?id=${dept.dept_id}">${dept.dept_name}</a></td>
											<td>${dept.emp_manager }</td>
											<td class="hidden-xs">${dept.updept_name }</td>
											<td><a href="dept?id=${dept.dept_id}"> <i class="icon edit"></i></a>
												&nbsp;
												<a onclick="return confirm('确认删除？')"
													href="dept/delete?id=${dept.dept_id}" > <i class="icon trash"></i> 
												</a></td>
										</tr>
									</c:forEach>
							</div>
						</div>
						<!-- /BOX -->
					</div>
				</div>
				<!-- /EXPORT TABLES -->
		
				<c:if test="${empty dept}">
					<tr>
						<td style="text-align: center;" colspan="5">暂无记录</td>
					</tr>
				</c:if>
			</tbody>
		</table>
				<c:if test="${totalPage > 1 }">
					<div class="page">
						<a <c:if test="${page!=1}">href="dept/form?page=1${queryString}"</c:if>
							class="${page == 1?'disable':''}">首页</a> <a
							<c:if test="${page!=1}">href="dept/form?page=${page-1}${queryString}"</c:if>
							class="${page == 1?'disable':''}">上一页</a> <a
							<c:if test="${page!=totalPage}">href="dept/form?page=${page+1 }${queryString}"</c:if>
							class="${page == totalPage?'disable':''}">下一页</a> <a
							<c:if test="${page!=totalPage}">href="dept/form?page=${totalPage }${queryString}"</c:if>
							class="${page == totalPage?'disable':''}">最后一页</a> 
							<span style = "float:right">${page}/${ totalPage} </span>
					</div>
				</c:if>
			</div>
		</div>
		</div>
	</div>
	</div>
	</div>
	</div>
	
</body>
</html>